package com.twohand.admin.Controller;

import com.twohand.admin.Service.ShortLinkService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/r")
public class ShortLinkController {
    @Autowired
    ShortLinkService shortLinkService;
    Logger log = LoggerFactory.getLogger(ShortLinkController.class);
    @GetMapping("/{shortLink}")
    void getShortLink(@PathVariable String shortLink, HttpServletResponse response) throws IOException {
        String longLink = shortLinkService.getLongLink(shortLink);
//        return "redirect:"+longLink;
        log.info(longLink);
        response.sendRedirect(longLink);
    }
}
